<?php


function smarty_function_db_fetchrow( $params, &$smarty )
{
	extract( $params );
	$table = !empty( $table ) ? trim( $table ) : "";
	$items = !empty( $items ) ? trim( $items ) : "";
	$condition = !empty( $condition ) ? trim( $condition ) : "";
	$varname = !empty( $varname ) ? trim( $varname ) : "";
	$necessaryParams = array( "table", "items", "condition", "varname" );
	$paramCount = count( $necessaryParams );
	$i = 0;
	for ( ;	$i < $paramCount;	++$i	)
	{
		if ( !isset( $necessaryParams[$i] ) )
		{
			$smarty->trigger_error( "db_FetchRow: missing '".$necessaryParams[$i]."' parameter" );
		}
		else
		{
			$$necessaryParams[$i] = trim( $$necessaryParams[$i] );
		}
	}
	$sqlCondition = "";
	$condition = trim( $condition );
	if ( !empty( $condition ) )
	{
		$sqlCondition = "WHERE (".$condition.")";
	}
	global $db;
	global $gDb;
	$table = $gDb['prefix'].$table;
	$sql = "SELECT ".$items." FROM {$table} {$sqlCondition}";
	$arr = $db->fetchrow( $sql );
	$smarty->assign( $varname, $arr );
	unset( $arr );
}

?>
